# -*- coding: utf-8 -*-
"""
@funcs: 全局环境变量，所有配置及全局变量最终集成到这里
"""
import json
import os
from kds_util.user_logbook import user_log as logger
from typing import List
from kds_util.json_config_mgr import ConfigMgr


class Envs:
    data_center_ip: str = ""    # 数据中心ip,由系统传送进来
    investor_id: str = ""   # 账号
    dest_url: str = ""
    dest_ip: str = ""
    dest_mysql_passwd: str = ""
    dest_investor: str = ""
    prev_trade_day: int = 0  # 真正交易日的前一个交易日，由最后一个板块日线给出，由于板块日线都是延迟一天即昨天的，因此刚好用来计算真正交易日的前一个交易日
    cur_trade_day: int = 0  # 当前交易日
    bk_end_time: str = ""
    will_end_time: str = ""
    white_plate_flag: bool = False  # 白盘标识
    dest_play_back: int = 0
    dest_play_start_time: str = ""  # 开始时间
    dest_play_end_time: str = ""  # 结束时间
    dest_codes: List[str] = []  # 默认为[]


def init_envs(investor_id):
    relative_config_path = "./etc"
    config_path = os.path.abspath(relative_config_path)
    config_file = f"{config_path}/{investor_id}_config.json"
    ConfigMgr.init(config_file)
    ConfigMgr.append_config("../../etc/global_config.json")

    try:
        Envs.investor_id = investor_id
        try:
            Envs.dest_play_back = ConfigMgr.get("dest_play_back")
        except:
            pass
        try:
            Envs.dest_play_start_time = ConfigMgr.get("dest_play_start_time")
        except:
            pass
        try:
            Envs.dest_play_end_time = ConfigMgr.get("dest_play_end_time")
        except:
            pass
        try:
            Envs.dest_codes = ConfigMgr.get("dest_codes")
        except:
            pass
        try:
            Envs.dest_url = ConfigMgr.get("dest_url")
        except:
            pass
        try:
            Envs.dest_mysql_passwd = ConfigMgr.get("dest_mysql_passwd")
        except:
            pass
    except Exception as exception:
        logger.info(str(exception))
    return

# init_envs()
